<script setup>
import {ref} from "vue";
import request9191 from "../../../utils/request9191.js";
import {ElMessage, ElMessageBox} from "element-plus";
import {Delete} from "@element-plus/icons-vue";
const clubData = ref()
const find123 = ref({
  cName: "",
  cType: ""
})
let pageNum = 1
let pageSize = 3
const total = ref(0)

const handleSizeChange = (val) => {
  pageSize = val
  getClubData()
}
const handleCurrentChange = (val) => {
  pageNum = val
  getClubData()
}
//分页

const getClubData = () =>{
  request9191({
    url: '/club/page',
    method: 'get',
    params: {
      page:pageNum,
      pageSize:pageSize,
      cName:find123.value.cName?find123.value.cName:null,
      cType:find123.value.cType?find123.value.cType:null
    }
  }).then((res)=>{
    clubData.value = res.data.data.rows
    total.value = res.data.data.total
  })
}

//管理员审批新增社团
const updateModStatus = (status , cid) =>{
  request9191({
    url: '/club/managerModStatus',
    method: 'put',
    params:{
      status:status,
      cid:cid
    }
  }).then((res)=>{

    if (res.data.data === 1){
      ElMessage.success("已通过")
    }else {
      ElMessage.info("已驳回")
    }

    getClubData()
  })
}

//管理员删除社团
const DeleteClub = (cid) => {
  ElMessageBox.confirm(
      '确认删除该条消息?',
      '温馨提示',
      {
        confirmButtonText:'确认',
        cancelButtonText:'取消',
        type:'warning'
      }
  )
      .then(()=>{
        request9191({
          url:'club',
          method:'delete',
          params:{
            cid:cid
          }
        }).then(() =>{
          ElMessage.success('删除成功')
          getClubData()
        })
      }).catch(() =>{
        ElMessage({
          type:'info',
          message:'已取消'
        })
  })
}

getClubData()

</script>

<template>
  <div class="clubAll">
    <el-form :inline="true" :model="find123" class="demo-form-inline">
      <el-form-item label="名称">
        <el-input v-model="find123.cName" placeholder="输入名称" clearable/>
      </el-form-item>
      <el-form-item label="类别">
        <el-input v-model="find123.cType" placeholder="输入类别" clearable/>
      </el-form-item>
      <el-button type="primary" @click="getClubData">搜索</el-button>
    </el-form>
    <el-table :data="clubData" class="peopleTable">
      <el-table-column prop="cid" label="ID" width="60px"/>
      <el-table-column prop="cname" label="社团名称"/>
      <el-table-column prop="ctype" label="社团类别"/>
      <el-table-column prop="cheader" label="社团团长"/>
      <el-table-column prop="cpeople" label="社团人数"/>
      <el-table-column prop="ccreateTime" label="社团成立时间"/>
      <el-table-column prop="ctypeNumber" label="社团编号"/>
      <el-table-column prop="ctypeNumber" label="状态" width="100">
        <template #default="scope">
          <el-tag v-if="scope.row.status === 0" type="warning">待审核</el-tag>
          <el-tag v-else-if="scope.row.status === 1" type="success">已通过</el-tag>
          <el-tag v-else type="danger">已驳回</el-tag>
        </template>
      </el-table-column>
      <el-table-column  label="审核">
          <template #default="scope">
            <el-button size="small" type="success" @click="updateModStatus('1',scope.row.cid)">通过</el-button>
            <el-button size="small" type="danger" @click="updateModStatus('2' , scope.row.cid)">驳回</el-button>
          </template>
      </el-table-column>

      <el-table-column label="操作">
        <template #default="scope">
          <el-button size="default" type="danger" @click="DeleteClub(scope.row.cid)">
            <el-icon><Delete /></el-icon>
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination background layout="prev,sizes, pager, next"
                   :page-sizes="[3,5]"
                   :total="total"
                   :page-size="pageSize"
                   @size-change="handleSizeChange"
                   @current-change="handleCurrentChange"

    />
  </div>

</template>

<style scoped>
.peopleTable{
  display: flex;
}
</style>